<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use phpDocumentor\Reflection\Types\Self_;

/**
 * App\Models\Area
 *
 * @property int $id
 * @property int $area_id 地区标识
 * @property int $p_id 上级id
 * @property int $user_id 用户id
 * @property string $name 城市名字
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area whereAreaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area wherePId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Area whereUserId($value)
 * @mixin \Eloquent
 */
class Area extends Model
{

    public function  next() {
        return $this->hasMany(Area::class,'p_id','area_id');
    }

    /**
     * 获取全国地址数据
     */
    public function getAreaList()
    {
        return \Cache::rememberForever('area',function () {
          self::wherePId(0)->with('next.next')->get()->toArray();
      });
    }
}
